package com.kun.controller.foreign;


import com.kun.entity.Comment;
import com.kun.result.Result;
import com.kun.service.impl.CommentServiceImpl;
import com.kun.util.SysConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.InetAddress;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SunKun
 * @since 2021-06-14
 */
@RestController
@CrossOrigin  //允许跨域
@ResponseBody
@RequestMapping("/kun/foreign/comment")
public class CommentController {
    @Autowired
    private CommentServiceImpl commentService;

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @PostMapping("/insertComment")
    public Result insertComment(@RequestBody Comment comment){
        try {
            comment.setState(SysConstant.COMMENT_STATE_NO);//未审核
            comment.setUserIp(InetAddress.getLocalHost().getHostAddress());//获取当前ip地址
            commentService.insertComment(comment);
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error();
        }
    }
}

